# Maintainer: Ivy Foster <iff@archlinux.org>
# Reference: PKGBUILD(5)

pkgname=sndio
pkgver=1.9.0
pkgrel=1
pkgdesc='A small audio and MIDI framework part of the OpenBSD project'
arch=(loong64 x86_64)
url='https://sndio.org'
license=(ISC)

# sndio can be built without libbsd, but there are a bunch of individual
# ISC-licensed files by different authors to extract the licenses from
# if done that way. Licenses are complicated.
depends=(alsa-lib libbsd)

provides=(libsndio.so)

source=(
	"https://sndio.org/sndio-$pkgver.tar.gz"
	"https://sndio.org/sndio-$pkgver.tar.gz.asc"
)
# Checksum source: https://www.sndio.org/sndio-$pkgver.tar.gz.sha256
sha256sums=(
	f30826fc9c07e369d3924d5fcedf6a0a53c0df4ae1f5ab50fe9cf280540f699a
	SKIP
)
validpgpkeys=(6B1A7447AAF091CCDD36BAA6015E339411694A6E)

backup=(etc/default/sndiod)

build() {
	cd "sndio-$pkgver"
	./configure --prefix=/usr --enable-alsa --with-libbsd
	make
}

package() {
	cd "sndio-$pkgver"

	make DESTDIR="$pkgdir/" install

	install -D -m 644 contrib/sndiod.service \
		"$pkgdir/usr/lib/systemd/system/sndiod.service"
	install -D -m 644 contrib/default.sndiod \
		"$pkgdir/etc/default/sndiod"

	install -d "$pkgdir/usr/share/licenses/sndio"
	# this is the most up-to-date license outside of bsd-compat,
	# which isn't being used in this build
	sed '/^ \*\//q' libsndio/sioctl.c > "$pkgdir/usr/share/licenses/sndio/LICENSE"
}
